/*
 **Ball and Plate program**
 
 This program runs the ball and plate experiment. For more information, see:
 
 The usage is
 "bandp init" initializes the matrices.
 "bandp run" runs the program once the matrices have already been initialized.
 "bandp" initializes the matrices and then runs the program. This is the equivalent to first running "bandp init" and then "bandp run". 
 
 */


#include "openCVincludes.h"

#include "init.h"
#include "run.h"
#include "run3a.h"

int flag;

int main (int argc, char * const argv[]) 
{
    int gui;
    if (argc==1){ //Default is to run both init and run with GUI.
        init();
        printf("Init finished successfully.\n");
        flag=run(gui=1);  // run program
    }
    else if ( strcmp(argv[1], "init")==0){
        //Measure time
        int64 tic=cvGetTickCount();
        double ticRate = cvGetTickFrequency()*1e06;
        init(); // Generate init file
        printf("Init finished successfully.\n");
        //Measure time
        int64 toc = cvGetTickCount();
        printf("\nInit took: %lf seconds\n", (double) (toc-tic) / ticRate );
    }
    else if( strcmp(argv[1], "run")==0) {
        // Read init file
        // Check flag
        /*			if (!flag)
         * {
         * std::cout << "The matrices have not been initialized. Please run \"bandp init\" first" << std::endl;
         * return 1;
         * }
         */
        flag=run(gui=0); // Run program
    }
    else if( strcmp(argv[1], "run3")==0) {
        // Read init file
        // Check flag
        /*			if (!flag)
         * {
         * std::cout << "The matrices have not been initialized. Please run \"bandp init\" first" << std::endl;
         * return 1;
         * }
         */
        flag=run3a(gui=0); // Run program
    }
    else if( strcmp(argv[1], "gui")==0) {
        // Read init file
        // Check flag
        /*			if (!flag)
         * {
         * std::cout << "The matrices have not been initialized. Please run \"bandp init\" first" << std::endl;
         * return 1;
         * }
         */
        flag=run(gui=1); // Run program
    }
    else if( strcmp(argv[1], "help")==0) {
        printf("\n");
        printf("bandp init : intializes program.\n");
        printf("bandp run  : runs program. Requires init to have been run previously\n");
        printf("bandp      : intializes and then runs program.\n");
        printf("\n");
    }
	return 0;
}
